package com.example.demo.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by zhangting on 31/03/2021.
 */

@Configuration
public class RabbitmqConfig {

    public static final String exchange_name="exchange_name";
    public static final String topic_queue_name_a ="atopic.queue.a";
    public static final String topic_queue_name_b ="btopic.queue.b";

    @Bean("topicExchange")
    public TopicExchange topicExchange() {
        return new TopicExchange(exchange_name);
    }

    @Bean("topicAQueue")
    public Queue topicAQueue() {
        return new Queue(topic_queue_name_a);
    }

    @Bean("topicBQueue")
    public Queue topicBQueue() {
        return new Queue(topic_queue_name_b);
    }

    @Bean
    public Binding bindingExchangeA(@Qualifier("topicAQueue") Queue  topicAQueue, @Qualifier("topicExchange") TopicExchange topicExchange) {
        return BindingBuilder.bind(topicAQueue).to(topicExchange).with("routkey.*");
    }


    @Bean
    public Binding bindingExchangeb(@Qualifier("topicBQueue") Queue  topicBQueue, @Qualifier("topicExchange") TopicExchange topicExchange) {
        return BindingBuilder.bind(topicBQueue).to(topicExchange).with("routkey.b");
    }

}
